package redisx

import (
	"time"

	"nosqlx/config"

	"github.com/redis/go-redis/v9"
)

var RedisClient *redis.Client

func init() {
	//redisx, err := enginex.GetRedis("", "admin", config.RedisAddr)
	redisx, err := GetRedis("", config.RedisPassword, config.RedisDNS)
	if err != nil {
		panic(err)
	}

	RedisClient = redisx
}

func GetRedis(username, password, addr string) (*redis.Client, error) {
	client := redis.NewClient(&redis.Options{
		Addr:                  addr,
		ClientName:            "RedisAddr",
		Dialer:                nil,
		OnConnect:             nil,
		Protocol:              0,
		Username:              username,
		Password:              password,
		DB:                    0,
		DialTimeout:           0,
		ReadTimeout:           time.Second,
		WriteTimeout:          time.Second,
		ContextTimeoutEnabled: false,
		PoolFIFO:              false,
		TLSConfig:             nil,
		Limiter:               nil,
		IdentitySuffix:        "",
	})

	return client, nil
}
